package com.wanho.java157.SystemSetting.controller;

import com.wanho.java157.SystemSetting.po.Employee;
import com.wanho.java157.SystemSetting.po.Login;
import com.wanho.java157.SystemSetting.service.EmployeeService;
import com.wanho.java157.SystemSetting.service.LoginService;
import com.wanho.java157.commons.util.vo.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/employee")
@SessionAttributes({"employee"})
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;


    @RequestMapping("/loginToCms")
    public String loginToCms(Login login,Model model){
        Employee employee = employeeService.selectEmployeeByEmployeeId(String.valueOf(login.getEmployeeId()));
        model.addAttribute("employee",employee);
        return "index";
    }

    @RequestMapping("/employeeCheck")
    public String employeeCheck(Model model){
        List<Employee> allEmployee=employeeService.selectAllEmployee();
        model.addAttribute("allEmployee",allEmployee);
        return "view/systemSettings/manage/index";
    }

    @RequestMapping("/employeeSearch")
    public String employeeSearch(String emmployeeId,String emmployeename,Model model){
        List<Employee> allEmployee=employeeService.selectEmployeeAmbiguousName(emmployeeId,emmployeename);
        model.addAttribute("allEmployee",allEmployee);
        return "view/systemSettings/manage/index";
    }

    @RequestMapping("/employeeAdd")
    public String employeeAdd(Employee employee,Model model){
        System.out.println(employee);
        return "view/systemSettings/manage/index";
    }


    @RequestMapping("/addCheck")
    @ResponseBody
    public JSONResult menuDelete(String parentemployeeId, Model model){
        System.out.println(parentemployeeId);


        JSONResult jsonResult = new JSONResult();
        jsonResult.setFlag(1);
        jsonResult.setMsg("新增成功");
//        if (delete){
//            jsonResult.setFlag(1);
//            jsonResult.setMsg("新增成功");
//            return jsonResult;
//
//        }
//        jsonResult.setFlag(0);
//        jsonResult.setMsg("新增失败");
        return jsonResult;

    }
}
